package com.cxl.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cxl.entity.Type;
import com.cxl.mapper.TypeMapper;
import com.cxl.service.ITypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 崔学磊
 * @since 2022-03-16
 */
@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper, Type> implements ITypeService {
    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private TypeMapper typeMapper;

    @Override
    public List<Type> typeList() {
        List<Type> types = null;
        if (redisTemplate.hasKey("types")) {
            types = redisTemplate.opsForList().range("types", 0, -1);
        } else {
            types = typeMapper.findAll();
            redisTemplate.opsForList().rightPushAll("types", types);
        }
        return types;
    }
}
